#include <iostream>



int QuickPowerMod(long long a, long long b, long long p){
    long long ans = 1;
    long long base = a;
    while(b){
        if (b % 2 == 1){
            ans = (ans*base)%p;
        }
        base = base*base;
        base = base%p;
        b = b / 2;
    }

    return ans;
}


/**
 * https://www.luogu.com.cn/problem/P1226
 * 快速幂
 */
int main(){
    long long a,b,p;
    std::cin >> a >> b >> p;

    std::cout << a << "^" << b << " mod " << p << "=" << QuickPowerMod(a, b,p);

    return 0;
}